package com.tetris.test;

import java.util.Random;

import android.content.Context;
import android.view.View;

public class TetrisView extends GraphicsView {

	//approximation of center of screen
	int center = (int) Math.floor(XtileCount / 2);
	//keeps track of what type of block is falling
	String control;
	
	//Constructor
	public TetrisView(Context context) {
		super(context);
		setFocusable(true);
		
		genTiles();	
	}
	Random randomgen = new Random();
	/**
	 * Generates a new random type of block at the top center of the screen.
	 */
	public void genNewBlock() {
		int randomBlock = randomgen.nextInt(7);
		switch (randomBlock) {
			case 0: //square block
				grid[center][0].setTile(1, true);
				grid[center + 1][0].setTile(1, true);
				grid[center][1].setTile(1, true);
				grid[center + 1][1].setTile(1, true);
				control = "SQUARE";
			case 1: //line block
				for(int i = -1; i < 3; i++) {
					grid[center + i][0].setTile(2, true);
				}
				control = "LINE";
			case 2: //t block
				for(int i = -1; i < 2; i++) {
					grid[center + i][0].setTile(3, true);
				}
				grid[center][1].setTile(3, true);
				control = "T";
			case 3: //l block
				for(int i = -1; i < 2; i++) {
					grid[center + i][0].setTile(4, true);
				}
				grid[center + 1][1].setTile(4, true);
				control = "L";
			case 4: //j block
				for(int i = -1; i < 2; i++) {
					grid[center + i][0].setTile(5, true);
				}
				grid[center - 1][1].setTile(5, true);
				control = "J";
			case 5: //s block
				grid[center][0].setTile(6, true);
				grid[center][1].setTile(6, true);
				grid[center + 1][0].setTile(6, true);
				grid[center - 1][1].setTile(6, true);
				control = "S";
			case 6: //z block
				grid[center][0].setTile(7, true);
				grid[center][1].setTile(7, true);
				grid[center - 1][0].setTile(7, true);
				grid[center + 1][1].setTile(7, true);
				control = "Z";
		}
	}
	
	

}
